package com.jiazhong.shixi.pauline_bookstore.controller;

import com.jiazhong.shixi.pauline_bookstore.bean.User;
import com.jiazhong.shixi.pauline_bookstore.mapper.UserMapper;
import com.jiazhong.shixi.pauline_bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserMapper userMapper;
    @RequestMapping("/login" )
    public JsonResult login(User user) {
        System.out.println(user);

        User u = userMapper.login(user);
        if (u == null) {
            //登录失败
            JsonResult result
                    = new JsonResult(false, 407, null, "账号或密码错误");
            return result;
        } else {
            // 登陆成功 将用户登陆信息给前端送过来 user_id
            JsonResult result = new JsonResult(true, 200, u.getId(), "");
            return result;
        }
    }
        @RequestMapping("/add")
        public JsonResult add(User user){
            userMapper.add(user);
            JsonResult result = new JsonResult(true,200,"success","");
            return result;

        }
    }

